{extend name="sitehome@style/base" /}
{block name="resources"}
<link rel="stylesheet" href="ADDON_WECHAT_CSS/wx_qrcode.css">
{/block}
{block name="main"}

<div class='qrcode-body'>
	<div class="options-btn">
		<button class="layui-btn" onclick="load_url()">添加自定义模板</button>
	</div>
	<div id="pictureIndex" class="ncsc-picture-folder">
		<div class="ncsc-album">
			<div style="clear:both;"></div>
			<ul id="albumList" >
			{foreach name="template_list" item="info"}
			<li onmouseover="checkShowThis(this);"  onmouseout="checkHideThis(this);" >
			{if condition="$info.is_check == 1 "} 
				<img src="{$info.template_url}" style="border:1px solid #0d73f9;"/>
			{else /}
				<img src="{$info.template_url}" style="border:1px solid #eee;"/>
			{/if}
					<div class="check" >
					{if condition="$info.is_check == 1 "}
						<div onclick="modifyWeixinQrcode({$info.id})" style="margin-top:60%;cursor:pointer;">
							<span>编辑</span>
						</div>
						{else /}
						<div style="margin-top:50%;cursor:pointer;" onclick="modifyWeixinQrcodeTemplateValid({$info.id})">
							<span >设为默认</span>
						</div>
						<div onclick="deleteWeixinQrcodeTemplateValid({$info.id})" style="cursor:pointer;">
							<span>删除</span>
						</div>
						<div onclick="modifyWeixinQrcode({$info.id})" style="cursor:pointer;">
							<span>编辑</span>
						</div>
						{/if}
					</div>
					<input type="hidden" class="id" value="{$info.id}"/>
					<input type="hidden" class="background" value="{$info.background}"/>
					<input type="hidden" class="nick_font_color" value="{$info.nick_font_color}"/>
					<input type="hidden" class="nick_font_size" value="{$info.nick_font_size}"/>
					<input type="hidden" class="is_logo_show" value="{$info.is_logo_show}"/>
					<input type="hidden" class="header_left" value="{$info.header_left}"/>
					<input type="hidden" class="header_top" value="{$info.header_top}"/>
					<input type="hidden" class="name_left" value="{$info.name_left}"/>
					<input type="hidden" class="name_top" value="{$info.name_top}"/>
					<input type="hidden" class="logo_left" value="{$info.logo_left}"/>
					<input type="hidden" class="logo_top" value="{$info.logo_top}"/>
					<input type="hidden" class="code_left" value="{$info.code_left}"/>
					<input type="hidden" class="code_top" value="{$info.code_top}"/>
					<div>
						{if condition="$info.is_check == 1 "} 
							<img src="ADDON_WECHAT_IMG/check_qrcode1.png" class="qrcode_img" style="position:absolute;top:0px;left:1px;"/>
						{else /} 
							<img src="ADDON_WECHAT_IMG/check_qrcode1.png" class="qrcode_img" style="position:absolute;top:0px;leftt:1px;display:none;"/>
						{/if}
					</div>
				</li>
			{/foreach}
			</ul>
		</div>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
function checkShowThis(event){
	$(".qrcode_button").hide();
	$(".check").hide();
	$(event).find(".qrcode_button").show();
	$(event).find(".check").show();
}
function checkHideThis(event){
	$(event).find(".qrcode_button").hide();
	$(event).find(".check").hide();
}

//上传配置
var repeat_flag = false;//防重复标识
function save(event){
	var background = $(event).parent().parent().children(".background").val();
	var nick_font_color = $(event).parent().parent().children(".nick_font_color").val();
	var nick_font_size = $(event).parent().parent().children(".nick_font_size").val();
	var is_logo_show = $(event).parent().parent().children(".is_logo_show").val();
	var header_left = $(event).parent().parent().children(".header_left").val();
	var header_top = $(event).parent().parent().children(".header_top").val();
	var name_left = $(event).parent().parent().children(".name_left").val();
	var name_top = $(event).parent().parent().children(".name_top").val();
	var logo_left =$(event).parent().parent().children(".logo_left").val();
	var logo_top = $(event).parent().parent().children(".logo_top").val();
	var code_left = $(event).parent().parent().children(".code_left").val();
	var code_top = $(event).parent().parent().children(".code_top").val();
	if(repeat_flag) return;
	repeat_flag = true;
	$.ajax({
		type : "post",
		url : "{:addon_url('Wechat://sitehome/qrcode')}",
		dataType : "JSON",
		data : {
			'background' : background,
			'nick_font_color' : nick_font_color,
			'nick_font_size' : nick_font_size,
			'is_logo_show' : is_logo_show,
			'header_left' : header_left,
			'header_top' : header_top,
			'name_left' : name_left,
			'name_top' : name_top,
			'logo_left' : logo_left,
			'logo_top' : logo_top,
			'code_left' : code_left,
			'code_top' : code_top
		},
		success : function(data) {
			repeat_flag = false;
		}
	})
}

//设置店铺的模板为默认
function modifyWeixinQrcodeTemplateValid(id){
	$.ajax({
		type : "post",
		url : "{:addon_url('Wechat://sitehome/qrcode')}",
		data : { 'id' : id },
		dataType : "JSON",
		success : function(data) {
		}
	})
}

function deleteWeixinQrcodeTemplateValid(id){
	$.ajax({
		type : "post",
		url : "{:addon_url('Wechat://sitehome/qrcode')}",
		data : { 'id' : id },
		dataType : "JSON",
		success : function(data) {
		}
	})
}

function load_url(){
	window.location.href = nc.url('Wechat://sitehome/qrcode/index');
}

function modifyWeixinQrcode(id){
	window.location.href = nc.url('Wechat://sitehome/qrcode/index', {'id' : id});
}
</script>
{/block}